<?php
    $url = new Url();
    $arr_tip_icon = LoadConfig::$arr_tip_icon;
?>
<script type="text/javascript">
    function ajaxUpdateTips(){
        var id = '<?php echo $data["id"]?>'
        var strUrl = "<?=$url->createUrl("tips/ajaxUpdateTips") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                title_tip:$("#title_tip").val(),
                url:$("#url").val(),
                position:$("#position").val(),
                type:$("#type").val(),
                color:$("#color").val(),
                icon:$("input[name=icon]:checked").val(),
                button:$("input[name=button]:checked").val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    history.go(-1);
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }            
        });
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <ul class="form4">
            <li class="clearfix"><label><strong>Tiêu đề </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width: 500px;" id="title_tip" value="<?php echo $data["title"];?>"/>
                </div>
            </li>
            <li class="clearfix"><label><strong>Link </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width: 500px;" id="url" value="<?php echo $data["url"];?>"/>
                </div>
            </li>
            <li class="clearfix"><label><strong>Thứ tự </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width: 500px;" id="position" value="<?php echo $data["position"];?>"/>
                </div>
            </li>
            <li class="clearfix"><label><strong>Loại </strong>:</label>
                <div class="filltext">
                    <select id="type">
                        <option value="0" <?php echo $data["type"]==0 ? 'selected="selected"':'';?>>Bình thường</option>
                        <option value="1" <?php echo $data["type"]==1 ? 'selected="selected"':'';?>>Tin hướng dẫn quy định</option>
                    </select>
                </div>
            </li>
            <li class="clearfix"><label><strong>Màu </strong>:</label>
                <div class="filltext">
                    <select id="color">
                        <?php foreach(LoadConfig::$arr_tip_color as $key_color=>$value_color){?>
                            <option value="<?php echo $key_color;?>" <?php echo $key_color==$data["color"] ? 'selected="selected"':'';?>><?php echo $value_color;?></option>
                            <?php }?>
                    </select>
                    <br/>
                </div>
            </li>
            <li class="clearfix"><label><strong>Icon </strong>:</label>
                <div class="filltext">
                    <?php foreach(LoadConfig::$arr_tip_icon as $key_icon=>$value_icon){ 
                        ?>
                        <input name="icon" type="radio" value="<?php echo $key_icon;?>" <?php echo $key_icon==$data["icon"] ? 'checked="checked"':'';?>>
                        <?php if($key_icon >0){ ?>                                        
                            <img src="<?php echo Yii::app()->params["static_url_cp"].'/images/'.$value_icon ?>"/>
                            <?php }else{?>
                            None!
                            <?php }?>
                        <?php }?>
                </div>
            </li>
            <li class="clearfix"><label><strong>Icon </strong>:</label>
                <div class="filltext">
                    <?php foreach(LoadConfig::$button_tips as $key_button=>$value_button){ 
                        ?>
                        <input name="icon" type="radio" value="<?php echo $key_button;?>" <?php echo $key_button==$data["button"] ? 'checked="checked"':'';?>>
                        <?php if($key_button >0){ ?>                                        
                            <img src="<?php echo Yii::app()->params["static_url_cp"].'/images/'.$value_button ?>"/>
                            <?php }else{?>
                            None!
                            <?php }?>
                        <?php }?>
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext">
                    <input id="button_save" type="button" value=" Sửa " class="btn-bigblue" onclick="ajaxUpdateTips();"> 
                    &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext" style="color: red;" id="show_error"></div>
            </li>
        </ul>
    </div>
</div>